package com.ysqcould.web.controller.curriculum;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.curriculum.domain.CourseType;
import com.ysqcould.curriculum.service.ICourseTypeService;

/**
 * 课程分类Controller
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@RestController
@RequestMapping("/curriculum/type")
public class CourseTypeController extends BaseController
{
    @Autowired
    private ICourseTypeService courseTypeService;

    /**
     * 查询课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseType courseType)
    {
        startPage();
        List<CourseType> list = courseTypeService.selectCourseTypeList(courseType);
        return getDataTable(list);
    }

    /**
     * 导出课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:export')")
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseType courseType)
    {
        List<CourseType> list = courseTypeService.selectCourseTypeList(courseType);
        ExcelUtil<CourseType> util = new ExcelUtil<CourseType>(CourseType.class);
        util.exportExcel(response, list, "课程分类数据");
    }

    /**
     * 获取课程分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(courseTypeService.selectCourseTypeById(id));
    }

    /**
     * 新增课程分类
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:add')")
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseType courseType)
    {
        return toAjax(courseTypeService.insertCourseType(courseType));
    }

    /**
     * 修改课程分类
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:edit')")
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseType courseType)
    {
        return toAjax(courseTypeService.updateCourseType(courseType));
    }

    /**
     * 删除课程分类
     */
    @PreAuthorize("@ss.hasPermi('curriculum:type:remove')")
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseTypeService.deleteCourseTypeByIds(ids));
    }


    @Log(title = "课程分类",businessType = BusinessType.UPDATE)
    @PostMapping("/changeTypeStatus")
    public AjaxResult changeTypeStatus(@RequestBody CourseType type ){
        return toAjax(courseTypeService.changeTypeStatus(type));
    }
}
